package cn.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.dao.ProjMapper;
import cn.domain.Api;
import cn.domain.Proj;
import cn.domain.ProjExample;
import cn.service.ProjService;
import cn.util.Pagination;

@Service
@Transactional(rollbackFor=Exception.class)
public class ProjServiceImpl implements ProjService {

	@Autowired
	private ProjMapper projMapper;

	@Override
	public void insert(Proj  proj) {
		projMapper.insert(proj);
	}


	@Override
	public int getAllCount(Proj record) {
		return projMapper.getAllCount(record);
	}


	@Override
	public List<Proj> getAlllist(Pagination pagination) {
		pagination.setStartRow((pagination.getPageIndex() - 1) * pagination.getPageSize());
		List<Proj> list = projMapper.getAlllist(pagination);
		return list;
	}


	@Override
	public void delete(String deleteId) {
		for(String id:deleteId.split(",")){
			Proj proj = projMapper.selectByPrimaryKey(Integer.parseInt(id));
			proj.setIsdel(1);
			projMapper.updateByPrimaryKey(proj);
		}
	}


	@Override
	public boolean getOne(Proj proj) {
		ProjExample example = new ProjExample();
		example.createCriteria().andCnameEqualTo(proj.getCname()).andIsdelEqualTo(0);
		List<Proj> projs = projMapper.selectByExample(example);
		if(!projs.isEmpty() && projs.size() > 0){
			return true;
		}
		return false;
	}


	@Override
	public Proj selectOne(String deleteId) {
		return projMapper.selectByPrimaryKey(Integer.parseInt(deleteId));
	}


	@Override
	public void update(Proj proj) {
		projMapper.updateByPrimaryKey(proj);
	}


	@Override
	public List<Proj> getAll() {
		return projMapper.getAll();
	}


	@Override
	public int getApiCount(Pagination pagination) {
		// TODO Auto-generated method stub
		return projMapper.getApiCount(pagination);
	}


	@Override
	public List<Api> getApiList(Pagination pagination) {
		// TODO Auto-generated method stub
		pagination.setStartRow((pagination.getPageIndex() - 1) * pagination.getPageSize());
		return projMapper.getApiList(pagination);
	}


	@Override
	public List<Proj> getProjsById(Integer aid) {
		ProjExample example = new ProjExample();
		example.createCriteria().andAidEqualTo(aid);		
		return projMapper.selectByExample(example);
	}

}
